
#include <malloc.h>
#include <QDebug>
#include "include/cluster.h"
#include "include/core.h"
#include "include/task.h"
#include "include/simul.h"
/**
 * @brief initCluster 根据集群id初始化集群
 * @param cluster_id 集群的id
 * @param rate 初始化的速率
 */
void initCluster(int cluster_id, double rate)
{
    //拿出cluster_id核心作为current_cluster
    current_cluster = &clusters[cluster_id-1];

    current_cluster->cluster_id = cluster_id;
    current_cluster->rate= rate;
    current_cluster->cores = init_core_list_head();
    current_cluster->isFailed = false;

    for(int i = 0; i < M; ++i){
        if(cores[i].owner_cluster == cluster_id){
            //将集群中的处理器队列也按照利用率从低到高排列
            core_list *New = new core_list;
            New->core = &cores[i];
            enqueue_utilization(New->core, current_cluster->cores);
        }
    }

}

global_domain *getCluster(int cluster_id)
{
    if(cluster_id == -1)
        return nullptr;

    for(int i = 0; i < cluster_num; ++i){
        if(clusters[i].cluster_id == cluster_id)
            return &clusters[i];
    }
    qDebug()<<"cluster_id:"<<cluster_id<<"Error: GetGlobalDom"<<endl;

    return nullptr;
}
